package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.service.PostService;
import com.yugao.fintech.draper.admin.param.PostDTO;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import com.yugao.fintech.draper.admin.param.PostQuery;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/post")
@RequiredArgsConstructor
@Tag(name = "系统岗位管理")
public class PostController {
	private final PostService postService;

	@Operation(summary = "查询岗位列表分页")
	@GetMapping(value = "/pageQuery")
	public ResultVO<PageResult<PostDTO>> pageQuery(@RequestBody PostQuery postQueryVo) {
		return ResultVO.success(PageResult.success(postService.pageQuery(postQueryVo)));
	}

	@Operation(summary = "添加岗位")
	@PostMapping(value = "/add")
	public ResultVO<Boolean> add(@RequestBody PostDTO postDTO) {
		return ResultVO.success(postService.addPost(postDTO));
	}

	@Operation(summary = "修改岗位")
	@PostMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody PostDTO postDTO) {
		return ResultVO.success(postService.updatePost(postDTO));
	}

	@Operation(summary = "删除岗位")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(postService.deletePost(id));
	}

	@Operation(summary = "查询岗位详细信息")
	@GetMapping(value = "/findById")
	public ResultVO<PostDTO> findById(Long id) {
		return ResultVO.success(postService.findById(id));
	}

	@Operation(summary = "获取全部岗位列表")
	@GetMapping(value = "/findAll")
	public ResultVO<List<PostDTO>> findAll() {
		return ResultVO.success(postService.findAll());
	}
}